﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace ConsoleApp
{
    /// <summary>
    /// 处理： redis.conf 中的注释 全去掉。
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            var path = Path.GetFullPath("../../../redis.conf");

            if (File.Exists(path))
            {
                var lines = File.ReadAllLines(path);

                var lstNode = new List<string>();

                var lst = new List<string>
                {
                    "# requirepass foobared",
                    "# masterauth <master-password>",
                    "# masteruser <username>"
                };

                foreach (var line in lines)
                {
                    var isOk = false;
                    foreach (var item in lst)
                    {
                        if (line.StartsWith(item))
                        {
                            isOk = true;
                            break;
                        }
                    }

                    if (!line.StartsWith("#") || isOk)
                    {
                        lstNode.Add(line);
                    }

                    if (line.StartsWith("# requirepass foobared"))
                    {
                        lstNode.Add("");
                        lstNode.Add("# slaveof <masterIP> <masterPort>");
                        lstNode.Add("");
                    }
                }

                var strs = string.Join("\r\n", lstNode).Trim().Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);

                var conf = string.Join("\r\n", strs);

            }

        }
    }
}
